package com.weiyi.mashangzhu.Roomer.Adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.weiyi.mashangzhu.Application.MyApp;
import com.weiyi.mashangzhu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by win7 on 2017/10/27.
 */

public class GridAdapter_Price extends ArrayAdapter<String> {
    private Context mContext;
    private int layoutResourceId;
    private List<String> mGridData = new ArrayList<String>();

    public GridAdapter_Price(Context context, int resource, List<String> objects) {
        super(context, resource, objects);
        this.mContext = context;
        this.layoutResourceId = resource;
        this.mGridData = objects;
    }

    public void setGridData(ArrayList<String> mGridData) {
        this.mGridData = mGridData;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
            convertView = inflater.inflate(layoutResourceId, parent, false);
            holder = new ViewHolder();
            holder.textView = (TextView) convertView.findViewById(R.id.tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (position == MyApp.search_price) {
            holder.textView.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
            holder.textView.setBackground(mContext.getResources().getDrawable(R.drawable.shape_blue_line_bg));
        }
        holder.textView.setText(mGridData.get(position));
        return convertView;
    }

    private class ViewHolder {
        TextView textView;
    }


}
